package com.yunlongn.httpclient.factory;

import org.springframework.beans.factory.FactoryBean;

/**
 *
 * @author yunlongn
 */
public class HttpServerFactoryBean implements FactoryBean<Object> {

    private final String className;
    private final String host;
    private Class<?> apiClass;

    public HttpServerFactoryBean(String className, String host) {
        this.className = className;
        this.host = host;
    }

    @Override
    public Object getObject()  {
        return HttpServerFactory.createProxy(apiClass, this.getClass().getClassLoader(), host);
    }

    @Override
    public Class<?> getObjectType() {
        try {
            apiClass = this.getClass().getClassLoader().loadClass(className);
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
        return apiClass;
    }
}
